package com.kedi.usercenter.read.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
* @Description:    usermapper
* @Author:         ytw
* @CreateDate:     2019/7/22 16:56
* @UpdateRemark:   修改内容
* @Version:        1.0
*/
@Mapper
public interface UserMapper {
    /**
     * 方法实现说明  根据密码和电话找
     * @author      ytw
     *@param         mPassword,phone
     * @return
     * @exception
     * @date        2019/7/22 16:47
     */
    @Select("select user.p_user_id,user.role_id,user.name,user.idcard,user.loginname,user.sex, user.password from phone left join user_phone on user_phone.p_phone_id =phone.p_phone_id " +
            " left join user on  user_phone.p_user_id=user.p_user_id " +
            " where user.password=#{password} and phone.code=#{code};")
    Map<String,Object> selectByNameAndPs(@Param("password") String mPassword, @Param("code") String phone);

    /**
     * 方法实现说明  根据身份证查询社区id
     * @author      ytw
     *@param         idcard
     * @return
     * @exception
     * @date        2019/7/22 16:48
     */
    @Select("SELECT communityc.communityc_id from communityc left join village on communityc.communityc_id=village.communityc_id left join elderly on  " +
            "village.village_id =elderly.village_id   where elderly.idcard=#{idcard} ")
    Map<String,Object> selectByIdcardfindName(@Param("idcard") String idcard);


    /**
     * 					方法实现说明
     * @author     		ytw
     * @param            phone
     * @return      		selectByPhone
     * @date        		2019/7/22 16:50
     */
    @Select("select user.p_user_id,user.role_id,user.name,user.idcard,user.loginname,user.sex from user left join user_phone on user_phone.p_user_id=user.p_user_id left join" +
            " phone on phone.p_phone_id=user_phone.p_phone_id where phone.code=${phone}")
    Map<String,Object> selectByPhone(@Param("phone") String phone);


    /**
     * 					方法实现说明  根据id 更新
     * @author      		ytw
     * @param         	map
     * @return			updateById
     * @date       		2019/7/22 16:50
     */
   /* @UpdateProvider(type=UserProvider.class,method = "updateUser")
    Integer updateById(Map map);*/


    /**
     * 根据用户的主键查询用户所拥有的系统资源地址
     * @author Zyred
     * @param userId 用户主键
     * @return
     */
   @Select("SELECT g.url FROM " +
           "administrator a, administrator_role_table b, administrator_role c, role_auth d," +
           "administrator_authority e, role_source f, auth_source g" +
           "WHERE" +
           "a.administrator_id = b.administrator_id" +
           "AND a.administrator_id = #{userId}" +
           "AND b.administrator_role_id = c.administrator_role_id" +
           "AND c.administrator_role_id = d.administrator_role_id" +
           "AND d.administrator_authority_id = f.administrator_authority_id" +
           "AND f.auth_source_id = g.auth_source_id")
    List<String> findUrlsByUserId(@Param("userId") String userId) throws Exception;

    /**
     *					 方法实现说明   根据登录名找用户id
     * @author      		 ytw
     * @param         	 loginname
     * @return
     * @date              2019/7/22 16:50
     */
    @Select("select user.p_user_id from user left join user_phone on user_phone.p_user_id=user.p_user_id left join " +
            "phone on phone.p_phone_id=user_phone.p_phone_id where user.loginname=${loginname};")
    Integer selectByloginname(@Param("loginname") String loginname);

    /**
    * 方法实现说明  根据社区区名找社区id
    * @author      ytw
    *@param
    * @return
    * @exception
    * @date        2019/8/1 12:41
    */
    @Select(" select * from communityc  where communityc_name=#{communityc_name}")
    Integer selectcommunitycId(Map map);

    @Select("select adress_name from user_address where p_user_id=#{p_user_id}")
    String selectpuseraddress(Map map);
}
